// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_PUR_PURCHASE_ORDER_ITEM
// * CreateDate    : 2011/8/16 10:16:41
// * Creater       : CodeSmith
// * LastChangeDate: 2011/8/16 10:16:41
// * LastChanger   : 2011/8/16 10:16:41
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Pur
{
/// <summary>
    /// PurPurchaseOrderItem
    /// </summary>
    public partial class PurPurchaseOrderItemBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objPurPurchaseOrderItemEntity">Entity</param>
        /// <returns>Entity</returns>
        public static PurPurchaseOrderItemEntity GetPurPurchaseOrderItem(PurPurchaseOrderItemEntity objPurPurchaseOrderItemEntity)
        {
            return DataAccess.SelectSingle<PurPurchaseOrderItemEntity>(objPurPurchaseOrderItemEntity);
        }
        public static PurPurchaseOrderItemEntity GetPuraseOrderItemByID(string itemID)
        {
            if (string.IsNullOrEmpty(itemID))
            {
                return null;
            }
            PurPurchaseOrderItemEntity entity = new PurPurchaseOrderItemEntity();
            entity.PurchaseItemId = itemID;
            return DataAccess.SelectSingle<PurPurchaseOrderItemEntity>(entity);
        }
        public static List<PurPurchaseOrderItemEntity> GetByPurchaseOrderID(string purchaseOrderID)
        {
            if (string.IsNullOrEmpty(purchaseOrderID))
            {
                return null;
            }
            PurPurchaseOrderItemEntity entity = new PurPurchaseOrderItemEntity();
            entity.PurchaseOrderId = purchaseOrderID;
            return DataAccess.Select<PurPurchaseOrderItemEntity>(entity);
        }
        public static DataSet GetDataSetByPurchaseOrderID(string purchaseOrderID)
        {
            if (string.IsNullOrEmpty(purchaseOrderID))
            {
                return null;
            }
            string sql = @"SELECT DISTINCT POI.*,P.*, CONVERT(DECIMAL(18,2),POI.QTY*POI.PRICE_NO_TAX) AS TOTAL_AMOUNT, 
CONVERT(NVARCHAR(10),PO.DELIVERY_PLAN_DATE,120) AS DELIVERY_PLAN_DATE,
V.TOTAL_ARRIVED_QTY
FROM PUR_PURCHASE_ORDER_ITEM POI
INNER JOIN PUR_PURCHASE_ORDER PO ON PO.PURCHASE_ORDER_ID = POI.PURCHASE_ORDER_ID
inner JOIN MST_PRODUCT P ON P.PRODUCT_ID = POI.PRODUCT_ID
LEFT JOIN VIEW_PURCHASE_ARRIVED_QTY V ON V.PURCHASE_ITEM_ID = POI.PURCHASE_ITEM_ID
LEFT JOIN DBO.PUR_PURCHASE_ORDER_ITEM_DETAIL A ON A.PURCHASE_ITEM_ID=POI.PURCHASE_ITEM_ID
WHERE POI.PURCHASE_ORDER_ID = '" + purchaseOrderID + "'";
            return DataAccess.SelectDataSet(sql);
        }

        public static DataTable GetPurchaseProductionDetailByPurchaseOrderID(string purchaseOrderID)
        {
            if (string.IsNullOrEmpty(purchaseOrderID))
            {
                return null;
            }
            string sql = @"SELECT DISTINCT b.QTY,POI.*,P.*, CONVERT(DECIMAL(18,2),POI.QTY*POI.PRICE_NO_TAX) AS TOTAL_AMOUNT, 
CONVERT(NVARCHAR(10),PO.DELIVERY_PLAN_DATE,120) AS DELIVERY_PLAN_DATE,
V.TOTAL_ARRIVED_QTY,D.PLAN_ORDER_CODE,E.PRODUCT_SPEC_OUT AS PRODUCT_SPEC_OUT_S
FROM PUR_PURCHASE_ORDER_ITEM POI
INNER JOIN PUR_PURCHASE_ORDER PO ON PO.PURCHASE_ORDER_ID = POI.PURCHASE_ORDER_ID
inner JOIN MST_PRODUCT P ON P.PRODUCT_ID = POI.PRODUCT_ID
LEFT JOIN VIEW_PURCHASE_ARRIVED_QTY V ON V.PURCHASE_ITEM_ID = POI.PURCHASE_ITEM_ID
LEFT JOIN DBO.PUR_PURCHASE_ORDER_ITEM_DETAIL A ON A.PURCHASE_ITEM_ID=POI.PURCHASE_ITEM_ID
LEFT JOIN DBO.PUR_APPLICATION_ITEM B ON B.APPLICATION_ITEM_ID=A.APPLICATION_ITEM_ID
LEFT JOIN DBO.PUR_APPLICATION C ON B.APPLICATION_ID=C.APPLICATION_ID
LEFT JOIN DBO.PROD_PLAN_ORDER D ON D.PLAN_ORDER_ID=C.PLAN_ORDER_ID
LEFT JOIN DBO.SALES_PROD_PLAN_APPLICATION_ITEM E ON D.APPLICATION_ITEM_ID=E.APPLICATION_ITEM_ID
WHERE POI.PURCHASE_ORDER_ID = '" + purchaseOrderID + "'";
            return DataAccess.SelectDataSet(sql).Tables[0];
        }

        #endregion

        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objPurPurchaseOrderItemEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertPurPurchaseOrderItem(PurPurchaseOrderItemEntity objPurPurchaseOrderItemEntity)
        {
            return DataAccess.Insert(objPurPurchaseOrderItemEntity);
        }

        public static bool InsertPurPurchaseOrderItem(List<PurPurchaseOrderItemEntity> objPurPurchaseOrderItemEntityList)
        {
            return DataAccess.Insert(objPurPurchaseOrderItemEntityList);
        }
        #endregion

        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objPurPurchaseOrderItemEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdatePurPurchaseOrderItem(PurPurchaseOrderItemEntity objPurPurchaseOrderItemEntity)
        {
            return DataAccess.Update(objPurPurchaseOrderItemEntity);
        }

        public static bool UpdatePurPurchaseOrderItem(List<PurPurchaseOrderItemEntity> objPurPurchaseOrderItemEntityList)
        {
            return DataAccess.Update<PurPurchaseOrderItemEntity>(objPurPurchaseOrderItemEntityList);
        }
        #endregion

        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objPurPurchaseOrderItemEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeletePurPurchaseOrderItem(PurPurchaseOrderItemEntity objPurPurchaseOrderItemEntity)
        {
            return DataAccess.Delete(objPurPurchaseOrderItemEntity);
        }

        public static bool DeletePurPurchaseOrderItem(List<PurPurchaseOrderItemEntity> objPurPurchaseOrderItemEntityList)
        {
            return DataAccess.Delete<PurPurchaseOrderItemEntity>(objPurPurchaseOrderItemEntityList);
        }
        #endregion

        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetPurPurchaseOrderItemAll()
        {
            return DataAccess.SelectAllDataSet<PurPurchaseOrderItemEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<PurPurchaseOrderItemEntity> GetPurPurchaseOrderItemAllList()
        {
            return DataAccess.SelectAll<PurPurchaseOrderItemEntity>();
        }
        #endregion
	}
	
	
}	

